package org.adream.account.rest.api;

import org.adream.account.model.LoginModel;
import org.adream.account.model.ResultModel;
import org.adream.account.service.ADreamServiceException;
import org.adream.account.service.LoginService;
import org.adream.account.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户操作
 * @author chenhaoyu
 *
 */
@Controller
@RequestMapping(value = "/personal/")
public class PersonalApiController {

	@Autowired
	LoginService loginService;

	@Autowired
	TagService tagService;

	/**
	 * 修改login的密码 ，盐保持原本不变
	 * 
	 * @param loginModel
	 *            — getPassword() 为空则重置密码为 000000，不为空则修改密码
	 * @return
	 * @author chenhaoyu
	 */
	@RequestMapping(value = "changePersonalPwd", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> changePersonalPwd(@RequestBody LoginModel loginModel) {
		try {
			if(loginModel == null || StringUtils.isEmpty(loginModel.getUid())) {
				return new ResultModel<String>(ResultModel.ERR_PARAM, "重置失败,请求参数有误", null);
			}
			loginService.changeLoginPwdByUid(loginModel);
			return new ResultModel<String>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, null);
		} catch (ADreamServiceException e) {
			return new ResultModel<String>(ResultModel.ERR_PARAM, e.getMessage(), null);
		}
	}
}